package com.yanqu.road.server.cmd.activity.jiuzhou;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.jiuzhou.CrossJiuZhouMgr;
import com.yanqu.road.server.manager.activity.jiuzhou.activity.CrossJiuZhouActivity;
import com.yanqu.road.server.protocol.*;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_JIU_ZHOU_GET_RANK_LIST, desc = "九州获取排行榜")
public class CrossJiuZhouGetRankCmd extends CrossCommand {

    int activityId;
    int rankType;
    int zoneType;
    long playerId;
    int pageNo;
    int pageSize;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JiuZhouProto.JiuZhouGetRankReqMsg reqMsg = JiuZhouProto.JiuZhouGetRankReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        rankType = reqMsg.getRankType();
        zoneType = reqMsg.getZoneType();
        playerId = packet.getPlayerId();
        pageNo = reqMsg.getPageNo();
        pageSize = reqMsg.getPageSize();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossJiuZhouActivity activity = CrossJiuZhouMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_JIU_ZHOU_ACTIVITY_NOT_EXIST;
            return;
        }
        ret = activity.getRankList(playerId, rankType, zoneType,pageNo,pageSize);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            JiuZhouProto.JiuZhouGetRankRespMsg.Builder builder = JiuZhouProto.JiuZhouGetRankRespMsg.newBuilder();
            builder.setRet(ret);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(ClientProtocol.U_JIU_ZHOU_GET_RANK_REQ, builder));
        }
    }
}
